/*******************************************************************
 *
 * Copyright (C), 2021-2022, LS, All rights reserved.
 *
 * Author      : 
 * Create Time : 2020-12-17
 * Version     : v0.1
 * Description : 
 *******************************************************************/
 
/*----------------------------Head file----------------------------*/
#include "wm.h"
#include "string.h"
#include "app_skip_alg.h"
#include "app_global_data.h"
#include "app_reset.h"

/*----------------------------macro file---------------------------*/

/*----------------------------type define--------------------------*/
enum {
    BL_ON_TEST = 0,
    BL_OFF_TEST,
    LCD_OFF_TEST   //Test adv consumption
};

/*----------------------------var define---------------------------*/
static uint8_t test_state = BL_ON_TEST;

/*-------------------------func declaration------------------------*/
static void fac_test_done_rst(void);
static void board_test_button_handle(void);
static void board_test_disp_sec_update(void);

/*-----------------------------------------------------------------*/

void wm_board_test_disp(void)
{
    wm_t wm;

    memset(&wm, 0, sizeof(wm));
    wm.cur_win = BOARD_TEST_WIN;
    wm.short_press_cb = board_test_button_handle;
    wm.auto_update_1hz_cb = board_test_disp_sec_update;
    wm.disp_off_cnt = DEFAULT_DISP_OFF_CNT;

    wm_info_set(&wm);

    app_disp_clear();
    app_disp_icon_set(ICON_MODE_COUNTDOWN_TIME);
    app_disp_icon_set(ICON_MODE_COUNTDOWN_NUM);
}

void wm_dev_test_disp(void)
{
    wm_t wm;

    memset(&wm, 0, sizeof(wm));
    wm.cur_win = DEV_TEST_PASS_WIN;
    wm.short_press_cb = fac_test_done_rst;
    wm.disp_off_cnt = DEFAULT_DISP_OFF_CNT;

    wm_info_set(&wm);

    app_skip_mode_set(SKIP_MODE_NULL);

    app_disp_clear();
    app_disp_pass();
    app_disp_update();

    wm_set_backlight_off_cnt(DISP_NEVER_OFF_CNT);
    app_disp_backlight_set(true);
}

static void fac_test_done_rst(void)
{
    app_ship_mode_reset();
}

static void board_test_button_handle(void)
{
    if(BL_ON_TEST == test_state) {
        app_disp_backlight_set(false);
        test_state = BL_OFF_TEST;
    }
    else if(BL_OFF_TEST == test_state) {
        wm_set_disp_off_cnt(0);
        test_state = LCD_OFF_TEST;
    }
    else {
        test_state = BL_ON_TEST;
    }
}

static void board_test_disp_sec_update(void)
{
    app_disp_bt_icon();
    app_skip_sec_update_handle();
    app_disp_skip_data();
    app_disp_icon_set(ICON_MODE_COUNTDOWN_TIME);
    app_disp_icon_set(ICON_MODE_COUNTDOWN_NUM);
    app_disp_update();
}
